clear;
clc;
%spline plotter
%read in knot values
knots=load('knots.txt');
plot3( knots(:,1), knots(:,2), knots(:,3), 'o');
hold on;
grid on;
%read in coefficients
coeffs = load( 'coeffs.txt' );
counter=1;
for i=1:4:length(knots)
    
    xknots(counter) = knots(i,1);
    counter = counter+1;
end
counter = 1;
for i=1:4
    yrange(i) = knots(i,2);
end
for r=1:length(yrange)
    for i=1:length(xknots)-1
        x = [xknots(i):0.1:xknots(i+1)];
        for j=1:length(x)
            y(j) = yrange(r);%knots(i,2);
        end
        a=coeffs(counter,2);
        b=coeffs(counter,3);
        c=coeffs(counter,4);
        d=coeffs(counter,5);
        z=a*(x.*1-x(1)).^3 + b*(x.*1-x(1)).^2 + c*(x.*1-x(1)) + d;
        plot3(x,y,z,'g');
        clear x;
        clear y;
        clear z;
        counter = counter+1;
    end
end
xlabel('X');
ylabel('Y');
zlabel('Z');

% [X,Y] = meshgrid(-2:0.2:2, 0:0.2:0.6);
% Z=sin(X.^2) - cos(Y.^2);
% mesh(X,Y,Z)